var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/typeof")), a = getApp(), e = {
    data: [],
    domain: "https://img14.360buyimg.com/n2/",
    cates: []
}, n = {
    page: 1,
    curItem: ""
};

Page({
    data: {
        StatusBar: a.globalData.StatusBar,
        CustomBar: a.globalData.CustomBar,
        bnAd_02: a.ad.bnAd_02,
        sharing: !1,
        cates: [],
        domain: "",
        curItem: "",
        scrollTop: 0,
        productList: [],
        pullUpOn: !0
    },
    ToMiniProgram: function(t) {
        var a = t.currentTarget.dataset.item, e = "" == a.quan ? encodeURIComponent(a.url) : encodeURIComponent(a.quan);
        wx.navigateToMiniProgram({
            appId: "wx13e41a437b8a1d2e",
            path: "/pages/proxy/union/union?spreadUrl=" + e + "&customerinfo=20200225KTVHJYTZ",
            success: function(t) {}
        });
    },
    onLoad: function() {
        a.watch(this, {
            curItem: function(t) {
                n.curItem = t, this.getProductList(1, !0);
            }
        });
    },
    onShow: function() {
        if (this.setData({
            sharing: !1
        }), "function" == typeof this.getTabBar && this.getTabBar() && this.getTabBar().setData({
            selected: 5
        }), 0 == e.data.length) {
            var n = this;
            wx.request({
                url: a.globalData.product_list_url,
                success: function(a) {
                    if ("object" == (0, t.default)(a.data) && null != a.data.domain) {
                        var r = a.data.data.map(function(t) {
                            return t.c;
                        }).filter(function(t, a, e) {
                            return e.indexOf(t) === a;
                        });
                        r.splice(0, 0, "全部"), e.data = a.data.data, e.cates = r, e.domain = a.data.domain, 
                        n.setData({
                            cates: r,
                            domain: e.domain,
                            curItem: a.data.curItem
                        });
                    }
                }
            });
        } else this.setData({
            cates: e.cates,
            curItem: e.data.length > 0 ? "" == this.data.curItem ? "全部" : this.data.curItem : "",
            domain: e.domain
        });
    },
    fenleiChange: function(t) {
        this.data.curItem != t.currentTarget.dataset.item && this.setData({
            curItem: t.currentTarget.dataset.item,
            scrollTop: 0
        });
    },
    ViewImage: function(t) {
        var a = t.currentTarget.dataset.src;
        a = a.replace(/(\/n1\/|\/n2\/|\/n3\/|\/n4\/|\/n5\/|\/n6\/|\/n7\/)/g, "/n0/"), wx.previewImage({
            urls: [ a ],
            current: a
        });
    },
    getProductList: function(t, a) {
        a = null != a && a, n.page = null == t ? 1 : t;
        var r = this.getPageData(e.data, n), i = !(r.data.data.length < r.data.per_page), u = this.data.productList;
        a ? u = [ r.data.data ] : u.push(r.data.data), this.setData({
            productList: u,
            pullUpOn: i
        });
    },
    getPageData: function(t, a) {
        "" != a.curItem && "全部" != a.curItem && (t = t.filter(function(t) {
            return t.c == a.curItem;
        }));
        var e = 10 * (a.page - 1), n = t.slice(e, e + 10);
        return {
            data: {
                per_page: 10,
                current_page: a.page,
                data: n
            }
        };
    },
    scrolltolower: function() {
        this.data.pullUpOn && (n.page = n.page + 1, this.getProductList(n.page));
    },
    onShareAppMessage: function(t) {
        return this.setData({
            sharing: !0
        }), {
            title: "酒友汇（酒优惠）品牌红酒优惠券，买红酒就上酒友汇。"
        };
    }
});